package model

type Ticker struct {
	CH   string `json:"ch"`
	Tick struct {
		Data []struct {
			Amount    string `json:"amount"`
			Direction string `json:"direction"`
			ID        int64  `json:"id"`
			Price     string `json:"price"`
			TS        int64  `json:"ts"`
		} `json:"data"`
		ID int64 `json:"id"`
		TS int64 `json:"ts"`
	} `json:"tick"`
	TS int64 `json:"ts"`
}

type DepthReturn struct {
	CH   string `json:"ch"`
	Tick struct {
		Asks    [][2]float64 `json:"asks"`
		Bids    [][2]float64 `json:"bids"`
		TS      int64        `json:"ts"`
		Version int64        `json:"version"`
	} `json:"tick"`
	TS int64 `json:"ts"`
}

//所有的卖单
func (this *DepthReturn) StatsAllAsk() float64 {
	//取最近50条需求数据
	result := 0.00
	for i := 0; i < len(this.Tick.Asks); i++ {
		v := this.Tick.Asks[i]
		result += v[0] * v[1]
	}
	return result
}

//最小卖单
func (this *DepthReturn) GetMinAsk() float64 {
	return this.Tick.Asks[0][0]
}

//倒数第5小卖单
func (this *DepthReturn) GetOpenAsk() float64 {
	return this.Tick.Asks[4][0]
}

//所有买单
func (this *DepthReturn) StatsAllBids() float64 {
	//取最近50条需求数据
	result := 0.00
	for i := 0; i < len(this.Tick.Bids); i++ {
		v := this.Tick.Bids[i]
		result += v[0] * v[1]
	}
	return result
}

//最大买单
func (this *DepthReturn) GetMaxBids() float64 {
	return this.Tick.Bids[0][0]
}

//第5大买单
func (this *DepthReturn) GetOpenBids() float64 {
	return this.Tick.Bids[4][0]
}
